package com.spring.nio.core.event.listener.event.constant;

import java.util.Arrays;

/**
 * @author: YSFY
 * @date: 2021-03-24 14:31
 * @pacage_name: com.spring.nio.core.event.listener.event.constant
 * @class_name: ExceptionEventType
 * @description: 异常事件类型
 */

public enum ExceptionEventTypeEnum {

    NIO_READ_EVENT_HANDLER(1, "NIO_READ_EVENT_HANDLER", "nio读事件处理异常"),
    NIO_WRITE_EVENT_HANDLER(2, "NIO_WRITE_EVENT_HANDLER", "nio写事件处理异常"),
    NIO_ACCEPT_EVENT_HANDLER(3, "NIO_ACCEPT_EVENT_HANDLER", "nio接入事件处理异常"),
    NIO_CONNECT_EVENT_HANDLER(4, "NIO_CONNECT_EVENT_HANDLER", "nio连接事件处理异常"),

    FILE_PARSE_HANDLER_IO_EXCEPTION(5, "FILE_PARSE_HANDLER_IO_EXCEPTION", "文件帧解析处理异常"),
    FILE_TRANSPORT_HANDLER_IO_EXCEPTION(6, "FILE_TRANSPORT_HANDLER_IO_EXCEPTION", "文件帧传输处理异常"),
    FILE_RECEIVE_HANDLER_IO_EXCEPTION(7, "FILE_RECEIVE_HANDLER_IO_EXCEPTION", "文件在线传输接收处理异常"),
    CHAT_BUSINESS_HANDLER_EXCEPTION(8, "CHAT_BUSINESS_HANDLER_EXCEPTION", "聊天业务处理异常");

    private Integer code;

    private String type, desc;

    ExceptionEventTypeEnum(Integer code, String type, String desc) {
        this.code = code;
        this.type = type;
        this.desc = desc;
    };

    public Integer getCode() {
        return code;
    }

    public String getType() {
        return type;
    }

    public String getDesc() {
        return desc;
    }

    public static ExceptionEventTypeEnum getEnumByCode(Integer code) {
        return Arrays.asList(ExceptionEventTypeEnum.values()).stream().filter(exceptionEventTypeEnum -> (exceptionEventTypeEnum.getCode().intValue() == code)).findFirst().get();
    }
}
